<?php
require("../../libchart/classes/libchart.php");
SWITCH ($_REQUEST['type'])
{
	case 'Vertical' :
	{
		$chart = new VerticalBarChart($_REQUEST['width'], $_REQUEST['height']);
		break;
	}
	case 'Horizontal' :
	{
		$chart = new HorizontalBarChart($_REQUEST['width'], $_REQUEST['height']);
		break;
	}
	case 'Pie' :
	{
		$chart = new PieChart($_REQUEST['width'], $_REQUEST['height']);
		break;
	}
	case 'Line' :
	{
		$chart = new LineChart($_REQUEST['width'], $_REQUEST['height']);
		break;
	}
}

$_REQUEST['title'] = trim(str_replace("[_spa_]", " ", $_REQUEST['title']));
$_REQUEST['points'] = trim(str_replace("[_spa_]", " ", $_REQUEST['points']));
$_REQUEST['values'] = trim(str_replace("[_spa_]", " ", $_REQUEST['values']));

$chart->setTitle($_REQUEST['title']);

if ($_REQUEST['type'] != 'Line')
{
	$dataSet = new XYDataSet();
	$values = explode("[*]", $_REQUEST['values']);
	for ($i=1;$i<count($values); $i++)
	{
		$data = explode("[,]", $values[$i]);
		if ($_REQUEST['type'] == 'Pie')
		{
			$dataSet->addPoint(new Point($data[0] . " (" . $data[1] . ")", $data[1]));
		}
		else
		{
			$dataSet->addPoint(new Point($data[0], $data[1]));
		}
	}
}
else
{
	$dataSet = new XYSeriesDataSet();
	$series = array(0);
	$points = explode("[,]", $_REQUEST['points']);
	$values = explode("[*]", $_REQUEST['values']);
	for ($i=1;$i<count($values); $i++)
	{
		$series[$i] = new XYDataSet();
		$data = explode("[,]", $values[$i]);
		for ($j=1;$j<count($data); $j++)
		{
			$series[$i]->addPoint(new Point($points[$j], $data[$j]));
		}
		$dataSet->addSerie($data[0], $series[$i]);
	}
}
$chart->setDataSet($dataSet);
$chart->render();
?>
